package cn.zhku.edu.feign.pojo.bo;

import cn.zhku.edu.feign.pojo.entry.Brand;
import cn.zhku.edu.feign.pojo.entry.Category;
import cn.zhku.edu.feign.pojo.entry.Product;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
public class ProductDoc {
    private Integer gid;

    private String type;

    private String goodsName;

    private BigDecimal goodsPrice;

    private String brandName;

    private String goodsDetail;

    private Integer sales;

    private String specifications;

    private List<String> suggestion;

    public ProductDoc(Product product, Brand brand, Category category){
        this.gid= product.getGid();
        this.type=category.getTypeName();
        this.goodsName=product.getGoodsName();
        this.goodsPrice=product.getGoodsPrice();
        this.brandName=brand.getBrandName();
        this.goodsDetail=product.getGoodsDetail();
        this.sales=product.getSales();
        this.specifications=product.getSpecifications();
        if(this.specifications!=null){
            String[] arr=this.specifications.split("\\n|\\s|[+]");
            this.suggestion= new ArrayList<>();
            suggestion.add(this.type);
            suggestion.add(this.goodsName);
            suggestion.add(this.brandName);
            Collections.addAll(suggestion,arr);
        }else{
            this.suggestion= Arrays.asList(this.type,this.goodsName,this.brandName);
        }

    }
}
